<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/24 0024
 * Time: 17:24
 */

namespace app\model\model;


class Bujian extends Base
{
    public function getList($where=false,$li){
        return $this->alias('n')
            ->join('Bujian_type nt','n.type_id=nt.id','left')
            ->field('n.*,nt.name as aname')
            ->order('n.id desc')
            ->where($where)
            ->paginate($li);
    }

    public function getListSelect($where = [],$sort=false){
        if($sort==false){
            return $this->where($where)->order('id desc')->select();
        }else{
            return $this->where($where)->order('sort asc')->select();
        }
    }

    /**
     * 添加
     * */
    public function add($data){
        return $this->data($data)->save();
    }
    /**
     * 获取
     * */
    public function getOne($id){
        return $this->alias('n')
            ->join('Bujian_type nt','n.type_id=nt.id','left')
            ->field('n.*,nt.name as aname')
            ->where(['n.id'=>$id])
            ->find();
    }
    /**
     * 修改
     * */
    public function up($where,$data){
        return $this->where($where)->update($data);
    }
    /**
     * 批量修改
     * */
    public function upAll($where,$data){
        return $this->where('id','in',$where)->update($data);
    }
    /**
     * 完全删除
     * */
    public function del($where){
        return $this->where($where)->delete();
    }
    public function delAll($where){
        return $this->where('id','in',$where)->delete();
    }
}